package everyday;

import java.util.HashSet;

/**
 * @author 兴趣使然黄小黄
 * @version 1.0
 * @date 2023/6/27 21:29
 * 575. 分糖果
 * https://leetcode.cn/problems/distribute-candies/
 */
public class Solution575 {

    // 使用 set 去重
    public int distributeCandies(int[] candyType) {
        int n = candyType.length;
        int maxCount = n / 2;
        HashSet<Integer> set = new HashSet<>();
        for (int item : candyType) {
            set.add(item);
            if (set.size() >= maxCount) {
                return maxCount;
            }
        }
        return set.size();
    }
}
